package org.jeecg.modules.quartz.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class RefreshSecretTest {
    public static void main(String[] args){
		// 初始化参数
        String path = "http://ip:port/CertShare/refreshsecret";
        String accessId = "abcd";
        String accessToken = "efgh";
        String requestPath = "/CertShare/queryCertInfo";
        String aesKey = accessId + "_" + requestPath;
        String sm3Sign = new SM3Utils().sm3(accessId + "#" + requestPath + "#" + accessToken);

        // 封装参数
        Map<String, String> head = new HashMap<>();
        head.put("accessId", accessId);
        head.put("accessToken", accessToken);
        Map<String, String> data = new HashMap<>();
        data.put("requestPath", requestPath);
        data.put("sign", sm3Sign);
        Map<String, Object> params = new HashMap<>();
        params.put("head", head);
        params.put("data", data);

        // 调用动态刷新秘钥接口
        String response = HttpUrls.doPost(path, JSON.toJSONString(params));

        // 解密响应结果获取动态SM2私钥和私钥过期时间
        JSONObject bodys = JSONObject.parseObject(response);
        String datas = bodys.getString("data");
        if (!datas.isEmpty()){
            String dataStr = SymmetricEncoder.AESDncode(aesKey , datas);
            System.out.println(dataStr);
        }

    }
}
